package com.nandi.emergencyinspection.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.luck.picture.lib.tools.ToastUtils

import com.nandi.emergencyinspection.R
import com.nandi.emergencyinspection.ui.activity.macro.MacroLookListActivity
import com.nandi.emergencyinspection.utils.Random
import com.nandi.emergencyinspection.weight.timeselect.ConfirmSelectDateCallback
import com.nandi.emergencyinspection.weight.timeselect.DayTimeEntity
import kotlinx.android.synthetic.main.activity_time_select.*
import kotlinx.android.synthetic.main.header_layout.*
import java.text.SimpleDateFormat
import java.util.*

class TimeSelectActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_time_select)
        left_icon.setOnClickListener { finish() }
        center_txt.text = "选择时间段"
        calendar_select.setistitleTimeShow(false) //隐藏控件顶部时间


        val selectDateCallback: ConfirmSelectDateCallback = object : ConfirmSelectDateCallback {
            override fun selectSingleDate(timeEntity: DayTimeEntity?) {
            }

            override fun selectMultDate(
                startTimeEntity: DayTimeEntity,
                endTimeEntity: DayTimeEntity
            ) {


                when (Random.timeCompare(startTimeEntity.startTime.toString(), getCurrentTime())) {
                    1 -> {
                        ToastUtils.s(this@TimeSelectActivity, "开始时间不能大于当前时间")
                    }
                    else -> {
                        setResult(
                            0x11,
                            Intent().putExtra("startTime", startTimeEntity.startTime.toString())
                                .putExtra("endTime", endTimeEntity.endTime.toString())
                        )
                        finish()
                    }
                }


            }
        }
        calendar_select.setConfirmCallback(selectDateCallback);
    }

    fun getCurrentTime(): String {

        val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd")// HH:mm:ss
        //获取当前时间
        val date = Date(System.currentTimeMillis())
        return simpleDateFormat.format(date)
    }
}